# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools


class FactorySummeryReport(models.Model):
    _name = "lift.base.factory.summery.report"
    _auto = False

    factory_id = fields.Many2one("tyibs.base.lift.factory", string=u'生产厂家', readonly=True)
    count_of_lift = fields.Integer(string=u'电梯楼', readonly=True)
    #percent = fields.Float(string=u'所占百分比', readonly=True)

    def init(self):
        tools.drop_view_if_exists(self._cr, 'lift_base_factory_summery_report')
        self._cr.execute("""CREATE or REPLACE view lift_base_factory_summery_report as (
                         SELECT
                            factory_id as id,
                            factory_id,
                            count(*) as count_of_lift
                            -- round((count(*)*100)::numeric/(select count(*) from tyibs_base_lift),2)as percent
                          from tyibs_base_lift
                          group by factory_id)""")

